package cn.szq.springframework.beans.factory.support;

import cn.szq.springframework.beans.BeansException;
import cn.szq.springframework.beans.factory.config.BeanDefinition;

import java.util.HashMap;
import java.util.Map;

/***
 * All rights Reserved, Designed By www.jx-lab.com
 * @Title: DefaultListableBeanFactory
 * @Description: 核心类实现(DefaultListableBeanFactory)
 * @author lixy
 * @date 2021/8/12 9:08
 * @version V1.0
 * @Copyright: www.jx-lab.com Inc. All rights reserved.
 * 注意：本内容仅限于众合景轩信息技术有限公司内部传阅，禁止外泄以及用于其他的商业目
 */
public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFactory implements BeanDefinitionRegistry {

    private Map<String, BeanDefinition> beanDefinitionMap = new HashMap<>();

    @Override
    protected BeanDefinition getBeanDefinition(String beanName) throws BeansException {
        BeanDefinition beanDefinition = beanDefinitionMap.get(beanName);
        if (beanDefinition == null){
            throw new BeansException("No bean named '" + beanName + "' is defined");
        }
        return beanDefinition;
    }

    @Override
    public void registerBeanDefinition(String beanName, BeanDefinition beanDefinition) {
        beanDefinitionMap.put(beanName, beanDefinition);
    }
}
